package cn.mrcode.fd.blog.auth;

import cn.mrcode.fd.blog.entity.LoginInfo;
import cn.mrcode.fd.blog.services.IAccountService;
import cn.mrcode.fd.plugin.security.SmartSecurity;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Set;

/**
 * ream需要的数据源api
 *
 * @author : zhuqiang
 * @version : V1.0
 * @date : 2015/12/26 22:32
 */
public class RealmSecurity implements SmartSecurity {
    @Autowired
    private IAccountService accountService;

    @Override
    public String getPassword(String username) {
        LoginInfo byAccount = accountService.findByAccount(username);
        return byAccount.getPassword();
    }

    @Override
    public Set<String> getRoleNameSet(String username) {
        Set<String> set = accountService.findRoleNameSet(username);
        return set;
    }

    @Override
    public Set<String> getPermissionNameSet(String roleName) {
        Set<String> set = accountService.findPermissionNameSet(roleName);
        return set;
    }
}
